<?php get_instance()->view('common/header');?>
<style>
    .content-btn-box,.content-box{margin-top:10px;}
    .container {
        width: 100%;
    }
    .add-tag-btn{line-height: 40px;}
    .option-item {
        margin-bottom: 5px;
        position: relative;
    }
    .del-tag-btn{font-size: 14px;line-height: 36px;display: block;margin-bottom: 4px;}
    .del-tag-btn a{color: red;}
    .add-img{margin-top: 9px;float: left;left: 0;}
    .radio-list{float: left;}
    .delete-btn{position: absolute;top: 0px;right: 64px;}
    .img-box .img{width: 200px;height: 130px}
    .webuploader-container > div:nth-child(2){width: 78px !important;height: 34px !important;}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title.' - 【位置：'.$position.'】';?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo $backUrl?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li><i class="fa fa-home"></i><a href="<?php echo getUrl('config/ads');?>">广告管理 </a><i class="fa fa-angle-right"></i></li>
                        <li><a href="<?php echo getUrl('config/ads/home?type='.$type);?>">新闻列表 </a><i class="fa fa-angle-right"></i></li>
                        <li><a href="javascript:void(0);"><?php echo $add ? '添加' : '编辑';?></a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN VALIDATION STATES-->
                    <div class="portlet box">
                        <div class="portlet-body form">
                            <!-- BEGIN FORM-->
                            <form action="<?php echo getUrl('config/ads/save')?>" class="form-horizontal" method="post" id="main-form" novalidate="novalidate">
                                <div class="form-body">
                                    <div class="form-group">
                                        <label class="control-label col-md-2"> 广告图片<span class="required">*</span></label>
                                        <div class="col-md-2 img-box">
                                            <div class="upload-img line">
                                                <div class="img-box">
                                                    <img class="img images" src="<?php echo ! $add ? $info['pic'] : getDefaultImg();?>">
                                                    <input name="pic" type="hidden" class="img-input" value="<?php echo ! $add ? $info['pic'] : '';?>"/>
                                                </div>
                                                <div id="uploader-demo" style="margin-top:10px;margin-left: 10px;">
                                                    <div id="fileList" class="uploader-list"></div>
                                                    <div class="filePicker">选择图片</div>
                                                </div>
                                                <div style="width:100%;height:10px;">
                                                    <div id="progress" style="height:100%;width:0;background-color:green;">&nbsp;</div>
                                                </div>
                                            </div>
                                        </div>
                                        <script type="text/javascript">
                                            $(function () {
                                                var uploader = WebUploader.create({
                                                    auto: true,
                                                    server: '<?php echo getUrl('config/ads/uploadImge');?>', // 文件接收服务端
                                                    pick: '.filePicker',
                                                    // 只允许选择图片文件
                                                    accept: {
                                                        title: 'Images',
                                                        extensions: 'gif,jpg,jpeg,bmp,png',
                                                        mimeTypes: 'image/*'
                                                    },
                                                    fileVal:'Filedata'
                                                });

                                                //文件上传过程中创建进度条实时显示。
                                                uploader.on( 'uploadProgress', function( file, percentage ) {
                                                    $('#progress').css( 'width', percentage * 100 + '%' );
                                                });

                                                // 文件上传成功，给item添加成功class, 用样式标记上传成功。
                                                uploader.on( 'uploadSuccess', function( file, response) {
                                                    $('.images').attr('src', response._raw);
                                                    $('.img-input').val(response._raw);
                                                });

                                                // 完成上传完了，成功或者失败，先删除进度条。
                                                uploader.on( 'uploadComplete', function( file ) {
                                                    $('#progress').width(0);
                                                });
                                            });
                                        </script>
                                    </div>
<!--                                    <div class="form-group">-->
<!--                                        <label class="control-label col-md-2">广告位置<span class="required">*</span></label>-->
<!--                                        <div class="col-md-7" >-->
<!--                                            <select class="form-control sel" name="ads_position" data-placeholder="请选择广告位置">-->
<!--                                                --><?php //foreach ($position as $k => $v): ?>
<!--                                                        <option value="--><?php //echo $k?><!--" selected >--><?php //echo $v?><!--</option>-->
<!--                                                --><?php //endforeach;?>
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                    </div>-->
                                    <div class="form-group">
                                        <label class="control-label col-md-2">广告名称<span class="required">*</span></label>
                                        <div class="col-md-7">
                                            <input class="form-control required" name="ads_name" type="text" value="<?php echo ! $add ? $info['ads_name'] : '';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">链接<span class="required">*</span></label>
                                        <div class="col-md-7">
                                            <input class="form-control required" name="url" type="text" value="<?php echo ! $add ? $info['url'] : '';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">开始时间<span class="required">*</span></label>
                                        <div class="col-md-7">
                                            <input class="form-control form-filter input-sm required " name="starttime" dp <?php if (!$add):?> readonly <?php endif;?> value="<?php echo ! $add ? dateFormat($info['starttime']) : '';?>"  type="text">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">结束时间<span class="required">*</span></label>
                                        <div class="col-md-7">
                                            <input class="form-control form-filter input-sm required " name="endtime" dp <?php if ($add):?> readonly <?php endif;?> value="<?php echo ! $add ? dateFormat($info['endtime']) : '';?>" type="text">
                                            <span class="help-block"><?php echo $day > 0 ? '温馨提示：该广告申请周期为'.$day.'天' : ''?></span>
                                        </div>
                                    </div>
                                    <div class="form-actionsc fluid">
                                        <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
                                            <input name="id" value="<?php echo ! $add ? $info['id'] : '';?>" type="hidden">
                                            <input name="merchant" value="<?php echo $merchant;?>" type="hidden">
                                            <input name="related_id" value="<?php echo $related_id;?>" type="hidden">
                                            <input name="ads_position" value="<?php echo $add ? $type : '';?>" type="hidden">
                                            <button class="btn green"><i class="fa fa-save"></i> 保存</button>
                                            <a class="btn default seach-btn" href="<?php echo $backUrl;?>"><i class="fa fa-chevron-left"></i> 返回</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- END VALIDATION STATES-->
                </div>
                <!-- END PAGE CONTENT-->
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $.e_validate.init('#main-form', {});

        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });
    });

    $(function(){
        setTimeout("$('.form-actions').width($('.form-body').innerWidth()).removeClass('hide');", '500');
        window.onresize = function(){
            $('.form-actions').width($('.form-body').innerWidth());
        }
    });
</script>
</body>
</html>